package com.squirrel.michale;

/**
 * @author guanhao 观浩
 * @version 1.0.0.0
 * @createTime 2023/2/13 7:48 AM
 * @company Michale Squirrel
 * @link
 * @description
 */
public class LeetCode0409 {

    public int longestPalindrome(String s) {
        int[] charFreq = new int[128];
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            charFreq[chars[i]]++;
        }

        int totalSum = 0;
        for (int i = 0; i < charFreq.length; i++) {
            int freq = charFreq[i];
            totalSum += freq / 2 * 2;
            if (freq % 2 == 1 && totalSum % 2 == 0) {
                totalSum++;
            }
        }
        return totalSum;
    }
}
